package com.bawei.module_home.discovery.adapter.provider

import android.widget.TextView
import androidx.core.content.ContextCompat
import androidx.recyclerview.widget.RecyclerView
import androidx.recyclerview.widget.StaggeredGridLayoutManager
import com.bawei.library_widget.CustomItemDecoration
import com.bawei.module_home.R
import com.bawei.module_home.discovery.adapter.CategoryItemAdapter
import com.bawei.module_home.discovery.entity.DiscoveryEntity
import com.blankj.utilcode.util.SizeUtils
import com.chad.library.adapter.base.provider.BaseItemProvider
import com.chad.library.adapter.base.viewholder.BaseViewHolder

/**
 * @Author : yaotianxue
 * @Time : On 2023/5/30 09:02
 * @Description : CardListProvider 专题策划
 */
class CardListProvider(override val itemViewType: Int, override val layoutId: Int) :BaseItemProvider<DiscoveryEntity.Item>() {
    override fun convert(helper: BaseViewHolder, item: DiscoveryEntity.Item) {
        var tvTitle = helper.getView<TextView>(R.id.tv_title)
        var tvActionTitle = helper.getView<TextView>(R.id.tv_action_title)
        tvTitle.text = item.data.header.title.toString()
        tvActionTitle.text = item.data.header.rightText.toString()
        //列表
        var rv = helper.getView<RecyclerView>(R.id.rv_category_view)
        var categoryItemAdapter = CategoryItemAdapter(R.layout.home_item_card_list_view,item.data.itemList as MutableList )
        rv.adapter = categoryItemAdapter
        rv.layoutManager = StaggeredGridLayoutManager(2,StaggeredGridLayoutManager.VERTICAL)
        if(rv.itemDecorationCount == 0){
            rv.addItemDecoration(CustomItemDecoration(2, context.resources.getDimension(com.bawei.library_common.R.dimen.dp_2).toInt()))//自定义分割线
        }
    }
}